const state = {
    allianceList: [],
    alliancePage: {},
    activityList: [],
    activityPage: {},
    orgList: [],
    orgPage: {},
    orgJgList: [],
    orgJgPage: {},
    orgLeaderList: [],
    orgLeaderPage: {},
    orgDynamicList: [],
    orgDynamicPage: {},
    orgProjectTypes: [],
    orgProjectTypePage: {},
    orgProjectList: [],
    orgProjectPage: {},
    orgPublishTypeList: [],
    orgPublishTypePage: {},
    orgPublishList: [],
    orgPublishPage: {},
    orgResultTypeList: [],
    orgResultTypePage: {},
    orgResultList: [],
    orgResultPage: {}
}
const actions = {
    saveAlliance: ({ commit}, payload) => {
        commit('SAVEALLIANCE', payload)
    },
    saveActivity: ({ commit }, payload) => {
        commit('SAVEACTIVITY', payload)
    },
    saveOrg: ({ commit }, payload) => {
        commit('SAVEORG', payload)
    },
    saveOrgJg: ({ commit }, payload) => {
        commit('SAVEORGJG', payload)
    },
    saveOrgLeader: ({ commit }, payload) => {
        commit('SAVEORGLEADER', payload)
    },
    saveOrgDynamic: ({ commit }, payload) => {
        commit('SAVEORGDYNAMIC', payload)
    },
    saveOrgProjectType: ({ commit }, payload) => {
        commit('SAVEORGPROJECTTYPE', payload)
    },
    saveOrgProject: ({ commit }, payload) => {
        commit('SAVEORGPROJECT', payload)
    },
    savePublishType: ({ commit }, payload) => {
        commit('SAVEORGPUBLISHTYPE', payload)
    },
    savePublish: ({ commit }, payload) => {
        commit('SAVEPUBLISH', payload)
    },
    saveResultType: ({ commit }, payload) => {
        commit('SAVEORGRESULTTYPE', payload)
    },
    saveResult: ({ commit }, payload) => {
        commit('SAVERESULT', payload)
    }
}
const mutations = {
    SAVEALLIANCE: (state, payload) => {
        if (payload.result.length === 0) {
            state.allianceList = []
        } else {
            state.allianceList = payload.result.map(item => {
                return {
                    id: item.id,
                    about: item.about,
                    name: item.name,
                    imgUrl: item.img_url
                }
            })
        }
        state.alliancePage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEACTIVITY: (state, payload) => {
        if (payload.result.length === 0) {
            state.activityList = []
        } else {
            state.activityList = payload.result.map(item => {
                return {
                    id: item.id,
                    publicAt: item.public_at,
                    title: item.title,
                    subTitle: item.sub_title,
                    isRecommend: item.is_recommend,
                    content: item.content,
                    allianceId: item.alliance_id,
                    origin: item.origin,
                    author: item.author,
                    state: item.state
                }
            })
        }
        state.activityPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORG: (state, payload) => {
        state.orgList = payload.result.map(item => {
            return {
                ...item,
                isAlliancer: Number(item.is_alliancer),
                allianceId: item.alliance_id,
                nameChar: item.name_char
            }
        })
        state.orgPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORGJG: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgJgList = []
        } else {
            state.orgJgList = payload.result.map(item => {
                return {
                    ...item,
                    organizationId: item.organization_id
                }
            })
        }
        state.orgJgPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORGLEADER: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgLeaderList = []
        } else {
            state.orgLeaderList = payload.result.map(item => {
                return {
                    ...item,
                    orgId: item.organization_id,
                    // organizationId: item.organization_id
                }
            })
        }
        state.orgLeaderPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORGDYNAMIC: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgDynamicList = []
        } else {
            state.orgDynamicList = payload.result.map(item => {
                return {
                    id: item.id,
                    publicAt: item.public_at,
                    title: item.title,
                    subTitle: item.sub_title,
                    content: item.content,
                    orgId: item.org_id,
                    origin: item.origin,
                    author: item.author,
                    state: item.state,
                    clickTimes: item.click_times
                }
            })
        }
        state.orgDynamicPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORGPROJECTTYPE: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgProjectTypes = []
        } else {
            state.orgProjectTypes = payload.result.map(item => {
                return {
                    id: item.id,
                    remark: item.remark,
                    names: item.name,
                    orgId: item.org_id,
                    state: item.state
                }
            })
        }
        state.orgProjectTypePage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORGPROJECT: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgProjectList = []
        } else {
            state.orgProjectList = payload.result.map(item => {
                return {
                    id: item.id,
                    publicAt: item.public_at,
                    completeAt: item.complete_at,
                    title: item.title,
                    subTitle: item.sub_title,
                    content: item.content,
                    orgId: item.org_id,
                    typeId: item.type_id,
                    state: item.state,
                    clickTimes: item.click_times
                }
            })
        }
        state.orgProjectPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORGPUBLISHTYPE: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgPublishTypeList = []
        } else {
            state.orgPublishTypeList = payload.result.map(item => {
                return {
                    id: item.id,
                    remark: item.remark,
                    state: item.state,
                    names: item.name,
                    orgId: item.org_id
                }
            })
        }
        state.orgPublishTypePage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEPUBLISH: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgPublishList = []
        } else {
            state.orgPublishList = payload.result.map(item => {
                return {
                    id: item.id,
                    gerneral: item.gerneral,
                    publicAt: item.public_at,
                    completeAt: item.complete_at,
                    title: item.title,
                    subTitle: item.sub_title,
                    content: item.content,
                    orgId: item.org_id,
                    typeId: item.type_id,
                    state: item.state,
                    clickTimes: item.click_times
                }
            })
        }
        state.orgPublishPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVEORGRESULTTYPE: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgResultTypeList = []
        } else {
            state.orgResultTypeList = payload.result.map(item => {
                return {
                    ...item,
                    names: item.name,
                    orgId: item.org_id
                }
            })
        }
        state.orgResultTypePage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
    SAVERESULT: (state, payload) => {
        if (payload.result.length === 0) {
            state.orgResultList = []
        } else {
            state.orgResultList = payload.result.map(item => {
                return {
                    id: item.id,
                    publicAt: item.public_at,
                    title: item.title,
                    subTitle: item.sub_title,
                    content: item.content,
                    orgId: item.org_id,
                    typeId: item.type_id,
                    state: item.state,
                    origin: item.origin,
                    author: item.author,
                    clickTimes: item.click_times
                }
            })
        }
        state.orgResultPage = {
            size: 10,
            total: payload.resultNum,
            number: payload.number
        }
    },
}

export default {
    state,
    actions,
    mutations
}